package com.example.demo1.service.servicelmpl;

import com.example.demo1.domain.User;
import com.example.demo1.repository.UserDao;
import com.example.demo1.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServicelmpl implements UserService{
@Resource
private UserDao userDao;

    @Override
    public User loginService(String uname, String password) {

        User user = userDao.findByUnameAndPassword(uname,password);

        if(user !=null){
            user.setPassword("");
        }
        return user;
    }

    @Override
    public User registService(User user) {
        if(userDao.findByUname(user.getUname())!=null){
        return null;
        }else{
            User newUser = userDao.save(user);
            if(newUser !=null){
                newUser.setPassword("");
            }
            return newUser;
        }
    }
}
